<?php


use Hyperf\Database\Migrations\Migration;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Schema\Schema;

class CreateGameTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('game', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏');
            $table->bigIncrements('id')->comment('主键');
            $table->addColumn('timestamp', 'created_at', ['precision' => 0, 'comment' => '创建时间'])->nullable();
            $table->addColumn('timestamp', 'updated_at', ['precision' => 0, 'comment' => '更新时间'])->nullable();
            $table->addColumn('timestamp', 'deleted_at', ['precision' => 0, 'comment' => '删除时间'])->nullable();
            $table->json('name')->nullable()->comment('名称');
            $table->char('code', 32)->nullable()->comment('标识');
            $table->char('platform', 32)->nullable()->comment('平台');
            $table->char('provider', 32)->nullable()->comment('provider');
            $table->char('icon', 64)->nullable()->comment('icon');
            $table->char('cover', 255)->nullable()->comment('cover');
            $table->tinyInteger('type')->comment('1视讯2老虎机3彩票4体育5电竞6捕猎7棋牌')->unsigned()->default(2);
            $table->tinyInteger('status')->comment('1正常')->unsigned()->default(1);
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->tinyInteger('rtp')->nullable()->comment('rtp')->unsigned();
            $table->char('hall')->comment('大厅')->default(0);
            $table->tinyInteger('demo')->comment('0否1是')->unsigned()->default(0);
            $table->tinyInteger('ingress')->nullable()->comment('支持终端1电脑2手机3电脑/手机网页')->unsigned();
            $table->bigInteger('view')->default(0)->unsigned();
            $table->index('code');
            $table->index('platform');
        });
        Schema::create('game_platform', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏平台');
            $table->bigIncrements('id')->comment('主键');
            $table->json('name')->nullable()->comment('名称');
            $table->char('code', 32)->nullable()->comment('标识');
            $table->char('icon', 64)->comment('icon');
            $table->tinyInteger('status')->comment('1正常')->unsigned()->default(1);
            $table->tinyInteger('rtp')->comment('rtp')->unsigned();
            $table->integer('sort')->comment('排序')->unsigned()->default(100);
            $table->json('config')->comment('配置');
        });
        Schema::create('game_category', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏分类');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('category_id')->comment('分类id')->unsigned();
            $table->bigInteger('game_id')->comment('游戏id')->unsigned();
        });
        Schema::create('game_tag', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏标签');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('tag_id')->comment('标签id')->unsigned();
            $table->bigInteger('game_id')->comment('游戏id')->unsigned();
        });
        Schema::create('game_symbol', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏币种');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('game_id')->comment('游戏id')->unsigned();
            $table->char('symbol', 8);
            $table->index('game_id');
        });
        Schema::create('game_account_rtp', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏账户rtp');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->char('code', 32)->comment('游戏平台');
            $table->char('symbol', 8)->comment('symbol');
            $table->char('provider', 16)->comment('provider');
            $table->tinyInteger('rtp')->comment('rtp')->unsigned()->default(0);
            $table->index(['user_id', 'code', 'provider']);
        });
        Schema::create('game_bet', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('下注表');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('game_id')->comment('游戏id')->unsigned();
            $table->string('game_name', 32)->nullable()->comment('游戏名称');
            $table->char('bet_id', 32)->comment('主注单id');
            $table->char('transaction_id', 32)->comment('交易id');
            $table->char('platform', 32)->comment('平台');
            $table->decimal('amount', 16, 4)->comment('下注额')->default(0);
            $table->decimal('payout', 16, 4)->comment('派彩额')->default(0);
            $table->decimal('result_amount', 16, 4)->comment('结果')->default(0);
            $table->smallInteger('rtp')->comment('rtp')->unsigned();
            $table->char('symbol', 8)->comment('symbol');
            $table->tinyInteger('result')->comment('1bet2win3lose')->unsigned()->default(1);
            $table->tinyInteger('status')->comment('处理0否1是2杀单')->unsigned()->default(0);
            $table->decimal('pump', 11, 4)->comment('抽水')->default(0);
            $table->timestamps();
            $table->index('user_id');
            $table->unique(['bet_id', 'transaction_id']);
        });
        Schema::create('game_favorite', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('游戏收藏');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->bigInteger('game_id')->comment('游戏id')->unsigned();
            $table->tinyInteger('status')->comment('1收藏')->unsigned()->default(0);
            $table->tinyInteger('view')->comment('1浏览')->unsigned()->default(0);
            $table->timestamp('last_at')->nullable()->comment('浏览时间');
            $table->index('user_id');
        });
        Schema::create('game_vip', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('vip等级');
            $table->bigIncrements('id')->comment('主键');
            $table->integer('level')->comment('等级')->unsigned();
            $table->char('icon', 64)->nullable();
            $table->decimal('amount', 11)->comment('达标')->unsigned()->default(0);
            $table->decimal('refunded', 11)->comment('奖励')->unsigned()->default(0);
            $table->decimal('week', 11)->comment('周奖励')->unsigned()->default(0);
            $table->decimal('month', 11)->comment('月奖励')->unsigned()->default(0);
            $table->decimal('day_total', 11)->comment('日提现总额')->unsigned()->default(0);
            $table->decimal('day_limit', 11)->comment('日提现限额')->unsigned()->default(0);
            $table->decimal('charge', 6)->comment('手续比例')->unsigned()->default(0);
        });
        Schema::create('game_account_vip', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('账户等级');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->integer('level')->comment('等级')->unsigned()->default(0);
            $table->timestamp('last_at')->nullable()->comment('完成时间');
            $table->index('user_id');
        });
        Schema::create('game_profit', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('收益');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->comment('用户id')->unsigned();
            $table->decimal('amount', 11)->comment('金额')->nullable();
            $table->tinyInteger('status')->comment('结算0否1是')->unsigned()->default(0);
            $table->date('start_at');
            $table->date('end_at');
        });
        Schema::create('game_user_register', function (Blueprint $table) {
            $table->engine = 'Innodb';
            $table->comment('用户注册下级');
            $table->bigIncrements('id')->comment('主键');
            $table->bigInteger('user_id')->unsigned();
            $table->bigInteger('parent_id')->unsigned();
            $table->date('date');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('game');
        Schema::dropIfExists('game_platform');
        Schema::dropIfExists('game_category');
        Schema::dropIfExists('game_tag');
        Schema::dropIfExists('game_symbol');
        Schema::dropIfExists('game_account_rtp');
        Schema::dropIfExists('game_bet');
        Schema::dropIfExists('game_favorite');
        Schema::dropIfExists('game_vip');
        Schema::dropIfExists('game_account_vip');
        Schema::dropIfExists('game_profit');
        Schema::dropIfExists('game_user_register');
    }
}
